#include <string>
#include <vector>
using namespace std;
/*
 * @lc app=leetcode.cn id=1624 lang=cpp
 *
 * [1624] 两个相同字符之间的最长子字符串
 */

// @lc code=start
class Solution {
public:
    int maxLengthBetweenEqualCharacters(string s) {
        vector<int> dict(27, -1); int res = -1;
        for (int i = 0; i < s.size(); i++) {
            if (dict[s[i] - 'a'] == -1) dict[s[i] - 'a'] = i;
            else {
                res = max(res, i - dict[s[i] - 'a'] - 1);
            }
        }
        return res;
    }
};
// @lc code=end

